<!-- showcollege函数未完成 -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <link rel="icon" href="../img/logo.png" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="../bootstrap-4.6.2-dist_and_jQuery/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../bootstrap-4.6.2-dist_and_jQuery/css/style.css">
    <script src="../bootstrap-4.6.2-dist_and_jQuery/js/jquery-3.7.0.js"></script>
    <script src="../bootstrap-4.6.2-dist_and_jQuery/js/bootstrap.js"></script>
</head>
<body>
    <!-- 导航栏 -->
    <div class="header">
        <div style="display: flex; align-items: center; margin-right: auto;">
            <img src="../img/logo2.png" alt="图片加载失败">
            <h2>教务管理系统</h2>
        </div>  
        
        <div class="dropdown">
            <div class="option">
                <div class="daohang" id="user-control">用户管理</div>
            </div>
            <div class="dropdown-content">
                <h4 id="student-control-head">学生管理</h4>
                <h4 id="teacher-control-head">老师管理</h4>
                <h4 id="secretary-control-head">教秘管理</h4>
                <h4 id="changepassword">修改密码</h4>
            </div>
        </div>
        <div class="dropdown">
            <div class="option">
                <div class="daohang" id="course-control">课程管理</div>
            </div>
            <div class="dropdown-content">
                
            </div>
        </div>
        <img src="../img/message.png" alt="图片加载失败" style="padding: 5px;" id="message-img">
    </div>
    <div class="container">
        <div class="content">
            <div style=" margin-bottom: 50px;">
                <div style="display: flex;">
                    <input id="search" class="search-course" type="text">
                    <button class="search-button" onclick="search()">搜索</button>
                </div>
            </div>
            <table id="user-control-table" class="table">
                <thead>
                    <tr id="table-head">
                        <th>学生id</th>
                        <th>学生姓名</th>
                        <th>学生账号</th>
                        <th>学生密码</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody id="user-control-tbody">
                    <tr>
                        <td>1</td>
                        <td>小明</td>
                        <td>xiaoming</td>
                        <td>password123</td>
                        <td>
                            <button class='btn btn-primary' onclick='editRow(this)'>修改</button>
                            <button class='btn btn-danger' onclick='deleteuser(1)'>删除</button>
                        </td>
                    </tr>
                </tbody>
            </table>
            <table id="course-control-table" class="table" style="display: none;">
                <thead>
                    <tr>
                        <th>课程名称</th>
                        <th>课程专业</th>
                        <th>课程学院</th>
                        <th>课程老师</th>
                        <th>课程教室</th>
                        <th>课程时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody id="course-control-tbody">

                </tbody>
            </table>
            <div style="display: flex; justify-content: center;">
                <p id="current_page"></p>
                <p style="margin-right: auto;" id="total_page"></p>
                <button class="btn btn-primary" id="adduserbtn" style="margin-right: 20px;" data-toggle="modal" data-target="#addModal">添加用户</button>
                <button class="btn btn-primary" id="addcoursebtn" style="margin-right: 20px; display: none;" data-toggle="modal" data-target="#addCourseModal">添加课程</button>
                <button class="btn btn-primary" style="margin-right: 20px;" onclick="prepage()" id="prepage">上一页</button>
                <button class="btn btn-primary" onclick="nextpage()" id="nextpage">下一页</button>
            </div>
        </div>
    </div>
    <div class="footer">
        教务管理系统 2023 from 摆烂小组
    </div>
    <!-- 修改数据的模态框 -->
    <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="editModalLabel">修改数据</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <!-- 修改表单 -->
              <form id="editForm">
                <div class="form-group">
                  <label for="editName">姓名</label>
                  <input type="text" class="form-control" id="editName" name="name" required>
                </div>
                <div class="form-group">
                  <label for="editUsername">账号</label>
                  <input type="text" class="form-control" id="editUsername" name="username" required>
                </div>
                <div class="form-group">
                  <label for="editPassword">密码</label>
                  <input type="text" class="form-control" id="editPassword" name="password" required>
                </div>
                <button type="button" class="btn btn-primary" onclick="saveChanges()">保存修改</button>
              </form>
            </div>
          </div>
        </div>
    </div>
    <!-- 添加用户的模态框 -->
    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="addModalLabel">添加数据</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <!-- 添加用户表单 -->
                <form id="addForm">
                <div class="form-group">
                    <label for="addName">姓名</label>
                    <input type="text" class="form-control" id="addName" name="name" required>
                </div>
                <div class="form-group">
                    <label for="addUsername">账号</label>
                    <input type="text" class="form-control" id="addUsername" name="username" required>
                </div>
                <div class="form-group">
                    <label for="addPassword">密码</label>
                    <input type="password" class="form-control" id="addPassword" name="password" required>
                </div>
                <button type="button" class="btn btn-primary" onclick="adduser()">保存修改</button>
                </form>
            </div>
            </div>
        </div>
    </div>
    <!-- 修改密码的模态框 -->
    <div class="modal fade" id="changepasswordModal" tabindex="-1" role="dialog" aria-labelledby="changepasswordModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="changepasswordModalLabel">修改密码</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <!-- 修改密码 -->
              <form id="changepasswordForm">
                <div class="form-group">
                  <label for="oldpassword">原密码</label>
                  <input type="text" class="form-control" id="oldPassword" name="oldpassword" required>
                </div>
                <div class="form-group">
                  <label for="newpassword">新密码</label>
                  <input type="password" class="form-control" id="newPassword" name="newpassword" required>
                </div>
                <div class="form-group">
                  <label for="confirmpassword">确认密码</label>
                  <input type="password" class="form-control" id="confirmPassword" name="confirmpassword" required>
                </div>
                <button type="button" class="btn btn-primary" onclick="changepassword()">保存修改</button>
              </form>
            </div>
          </div>
        </div>
    </div>
    <!-- 录入课程 -->
    <div class="modal fade" id="addCourseModal" tabindex="-1" role="dialog" aria-labelledby="addCourseModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="addCourseModalLabel">录入课程</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                    <!-- 表单 -->
                    <form id="addCourseForm">
                        <div class="form-group">
                            <label for="courseName">课程名称</label>
                            <input type="text" class="form-control" id="courseName" name="courseName" required>
                        </div>
                        <div class="form-group">
                            <label for="coursemajor">课程专业</label>
                            <input type="text" class="form-control" id="coursemajor" name="coursemajor" required>
                        </div>
                        <div class="form-group">
                            <label for="courseschool">课程学院</label>
                            <input type="text" class="form-control" id="courseschool" name="courseschool" required>
                        </div>
                        <div class="form-group">
                            <label for="courseTeacher">任课教师</label>
                            <input type="text" class="form-control" id="courseTeacher" name="courseTeacher" required>
                        </div>
                        <div class="form-group">
                            <label for="courseclassroom">课程教室</label>
                            <input type="text" class="form-control" id="courseclassroom" name="courseclassroom" required>
                        </div>
                        <div class="form-group">
                            <label for="coursetime">课程时间</label>
                            <input type="text" class="form-control" id="coursetime" name="coursetime" required>
                        </div>

                        <button type="submit" class="btn btn-primary">提交</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- 修改课程 -->
    <div class="modal fade" id="changeCourseModal" tabindex="-1" role="dialog" aria-labelledby="changeCourseModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="changeCourseModalLabel">修改课程</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                    <!-- 表单 -->
                    <form id="changeCourseForm">
                        <div class="form-group">
                            <label for="courseName1">课程名称</label>
                            <input type="text" class="form-control" id="courseName1" name="courseName1" required>
                        </div>
                        <div class="form-group">
                            <label for="coursemajor1">课程专业</label>
                            <input type="text" class="form-control" id="coursemajor1" name="coursemajor1" required>
                        </div>
                        <div class="form-group">
                            <label for="courseschool1">课程学院</label>
                            <input type="text" class="form-control" id="courseschool1" name="courseschool1" required>
                        </div>
                        <div class="form-group">
                            <label for="courseTeacher1">任课教师</label>
                            <input type="text" class="form-control" id="courseTeacher1" name="courseTeacher1" required>
                        </div>
                        <div class="form-group">
                            <label for="courseclassroom1">课程教室</label>
                            <input type="text" class="form-control" id="courseclassroom1" name="courseclassroom1" required>
                        </div>
                        <div class="form-group">
                            <label for="coursetime1">课程时间</label>
                            <input type="text" class="form-control" id="coursetime1" name="coursetime1" required>
                        </div>

                        <button type="submit" class="btn btn-primary">提交</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- 通知信息 -->
    <div class="modal fade" id="messageModal" tabindex="-1" role="dialog" aria-labelledby="messageModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="messageModalLabel">通知信息</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                    <div id="messagelist">

                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 提示信息 -->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">提示消息</h5>
            </div>
            <div class="modal-body">
                <b id="message">这是提示信息</b>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>
            </div>
        </div>
    </div>
    <script>//显示提示信息
        function showmessage(message){
            $('#message').text(message)
            $('#exampleModal').modal('show');
        }
    </script>
    <!-- 导航栏点击事件，显示数据部分 -->
    <script>
        $(function(){
            //用户管理子菜单
            $('.dropdown-content > h4').click(function() {
                // 获取被点击的 h4 元素的 id 属性值
                var clickedId = $(this).attr('id');
                
                // 根据 id 执行相应的函数
                switch (clickedId) {
                    case 'student-control-head':
                        user = "student";
                        user_ch = "学生";
                        showuser();
                        break;
                    case 'teacher-control-head':     
                        user = "teacher";                
                        user_ch = "老师";
                        showuser();
                        break;
                    case 'secretary-control-head':
                        user = "secretary";
                        user_ch = "教秘";
                        showuser();
                        break;
                    case 'changepassword':
                        $('#changepasswordModal').modal('show');
                        break;
                }
            });
            // 导航栏菜单
            $('.daohang').click(function(){
                var clickid = $(this).attr("id");
                switch(clickid) {
                    case 'user-control':
                        user = "student";
                        showuser();
                        break;
                    case 'course-control':
                        current = 2;
                        current_page = 1;
                        showcourse();
                        break;
                }
            });
            // 修改课程表单提交事件
            $("#changeCourseForm").submit(function (event) {
                // 阻止默认的表单提交行为
                event.preventDefault();

                // 获取表单数据
                var data = {
                    courseName: $("#courseName1").val(),
                    coursemajor: $("#coursemajor1").val(),
                    courseschool: $("#courseschool1").val(),
                    courseTeacher: $("#courseTeacher1").val(),
                    courseclassroom: $("#courseclassroom1").val(),
                    coursetime: $("#coursetime1").val(),
                    courseid : course_id
                };
                // 获取其他课程信息的输入框数据

                // 在这里可以通过 AJAX 将数据发送到后端进行插入数据库的操作
                $.ajax({
                    url: "adminchangecourse",
                    type: "POST",
                    data: data,
                    dataType: "text",
                    success: function (data) {//返回是否修改成功
                        if (data == "true")
                            showmessage("修改成功")
                        showcourse();
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        showmessage("修改课程失败");
                        console.log(textStatus + ': ' + errorThrown);
                    }
                });

                // 关闭模态框
                $("#changeCourseModal").modal("hide");
            });
            //添加课程表单提交事件
            $("#addCourseForm").submit(function (event) {
                // 阻止默认的表单提交行为
                event.preventDefault();

                // 获取表单数据
                var data = {
                    courseName: $("#courseName").val(),
                    coursemajor: $("#coursemajor").val(),
                    courseschool: $("#courseschool").val(),
                    courseTeacher: $("#courseTeacher").val(),
                    courseclassroom: $("#courseclassroom").val(),
                    coursetime: $("#coursetime").val()
                };
                // 获取其他课程信息的输入框数据

                // 在这里可以通过 AJAX 将数据发送到后端进行插入数据库的操作
                $.ajax({
                    url: "admincourseluru",
                    type: "POST",
                    data: data,
                    dataType: "text",
                    success: function (data) {//返回是否修改成功
                        if (data == "true")
                            showmessage("录入成功")
                        showcourse();
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        showmessage("录入课程失败");
                        console.log(textStatus + ': ' + errorThrown);
                    }
                });

                // 关闭模态框
                $("#addCourseModal").modal("hide");
            });
            //消息通知点击事件
            $("#message-img").click(function(){
                data={
                    receive_identity : "adminer",
                    receive_id : allCookies['adminer_id']
                };
                $.ajax({
                    url: "showmessage",
                    type:"POST",
                    data: data,
                    dataType:"text",
                    success:function(data){//返回值为发送人是谁,消息内容
                        var html="";
                        var arr=data.split(";");
                        console.log(arr);
                        for(let i = 0; i < arr.length-1; i+=2){
                            html+=  "<div class='message'>"+
                                        "<b>"+arr[i]+"</b>"+
                                        "<p>"+arr[i+1]+"</p>"+
                                    "</div>"+
                                    "<hr>";
                        }
                        if (arr == ""){
                            html+="<p>暂无消息</p>"
                        }
                        $("#messagelist").html(html);
                        $("#messageModal").modal('show'); 
                    },
                    error: function(jqXHR, textStatus, errorThrown){
                        showmessage("获取通知失败");
                        console.log(textStatus + ': ' + errorThrown);
                    }
                }); 
            });
            showuser();
        });
        var current;
        var course_id
        var user="student";
        var user_ch = "学生" 
        var userid;
        var allCookies = parseCookies();
        var current_page = 1;//当前页数
        var total_page;//总页数
        var recordsperpage = 5;//每页的记录数
        // 修改课程
        function changecourse(n, button){
            course_id = n;
            // console.log(course_id);
            // console.log("1111");
            var row = button.closest("tr");
            $("#courseName1").val(row.cells[0].textContent);
            $("#coursemajor1").val(row.cells[1].textContent);
            $("#courseschool1").val(row.cells[2].textContent);
            $("#courseTeacher1").val(row.cells[3].textContent);
            $("#courseclassroom1").val(row.cells[4].textContent);
            $("#coursetime1").val(row.cells[5].textContent);
            $('#changeCourseModal').modal('show');
        }
        //删除课程
        function deletecourse(n){
                data = {
                    course_id : n
                };
                // console.log(data.course_id);
                $.ajax({
                url: "admindeletecourse",
                type: "POST",
                data: data,
                dataType: "text",
                success: function (data) {//返回是否修改成功
                    if (data == "true")
                        showmessage("删除成功")
                    showcourse();
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    showmessage("删除课程失败");
                    console.log(textStatus + ': ' + errorThrown);
                }
            });
        }
        //显示课程信息
        function showcourse() {
            current = 2;
            $("#user-control-table").hide();
            $("#course-control-table").show();
            $("#adduserbtn").hide();
            $("#addcoursebtn").show();
            data = {
                current_page1: current_page,
                recordsperpage1: recordsperpage
            };
            if ($("#search").val() != "") {
                data.search = $("#search").val();
            }
            $.ajax({
                url: "adminshowcourse",
                type: "POST",
                data: data,
                dataType: "text",
                success: function (data) {//返回7个值,课程名称，专业，学院，老师，教室，时间，课程id
                    var html = "";
                    var arr = data.split(";");
                    total_page = Math.floor((arr[0] - 1) / recordsperpage) + 1;
                    console.log(arr);
                    for (var i = 1; i < arr.length - 1; i += 7) {
                        html += "<tr>" +
                                    "<td>" + arr[i] + "</td>" +
                                    "<td>" + arr[i + 1] + "</td>" +
                                    "<td>" + arr[i + 2] + "</td>" +
                                    "<td>" + arr[i + 3] + "</td>" +
                                    "<td>" + arr[i + 4] + "</td>" +
                                    "<td>" + arr[i + 5] + "</td>" +
                                    "<td>" +
                                        "<button class='btn btn-primary' style='margin-right : 10px;' onclick='changecourse("+arr[i+6]+", this)'>修改</button>"+
                                        "<button class='btn btn-danger' onclick='deletecourse("+arr[i+6]+")'>删除</button>"+
                                    "</td>"+

                                "</tr>";
                    }
                    $("#course-control-tbody").html(html);
                    var currentPageElement = document.getElementById("current_page");
                    currentPageElement.textContent = current_page;
                    var currentPageElement = document.getElementById("total_page");
                    currentPageElement.textContent = "/" + total_page;
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    showmessage("获取课程失败");
                    console.log(textStatus + ': ' + errorThrown);
                }
            });
        }

        //显示用户信息
        function showuser(){
            current = 1;
            var head = "";
            head += "<th>"+user_ch+"id</th>" +
                    "<th>"+user_ch+"姓名</th>" +
                    "<th>"+user_ch+"账号</th>" +
                    "<th>"+user_ch+"密码</th>" +
                    "<th>操作</th>";
            $("#table-head").html(head);
            $("#user-control-table").show();
            $("#course-control-table").hide();
            $("#adduserbtn").show();
            $("#addcoursebtn").hide();
            data={
                user : user, 
                current_page1 : current_page,
                recordsperpage1 : recordsperpage,
            };
            if ($("#search").val() != ""){
                data.search=$("#search").val();
            }
            $.ajax({
                url: "showuser",
                type:"POST",
                data: data,
                dataType:"text",
                success:function(data){//id，姓名，账号，密码
                    var html="";
                    var arr=data.split(";");
                    total_page = Math.floor((arr[0]-1)/recordsperpage)+1;
                    console.log(arr);
                    for(var i = 1; i < arr.length-1; i+=4){
                        html+= "<tr>"+
                                    "<td>"+arr[i]+"</td>"+
                                    "<td>"+arr[i+1]+"</td>"+
                                    "<td>"+arr[i+2]+"</td>"+
                                    "<td>"+arr[i+3]+"</td>"+
                                    "<td>" +
                                        "<button class='btn btn-primary' style='margin-right : 10px;' onclick='editRow(this)'>修改</button>"+
                                        "<button class='btn btn-danger' onclick='deleteuser("+arr[i]+")'>删除</button>"+
                                    "</td>"+
                                "</tr>";

                    }
                    $("#user-control-tbody").html(html);
                    var currentPageElement = document.getElementById("current_page");
                    currentPageElement.textContent = current_page;
                    var currentPageElement = document.getElementById("total_page");
                    currentPageElement.textContent = "/"+total_page;  
                },
                error: function(jqXHR, textStatus, errorThrown){
                    showmessage("获取用户信息失败");
                    console.log(textStatus + ': ' + errorThrown);
                }
            });        
        }
        //上一页
        function prepage() {
            if (current_page > 1) {
                current_page -= 1
                if(current == 1){
                    showuser();
                }
                else if (current == 2){
                    showcourse();
                }
            }
        }
        //下一页
        function nextpage() {
            if (current_page + 1 <= total_page) {
                current_page += 1;
                if(current == 1){
                    showuser();
                }
                else if (current == 2){
                    showcourse();
                }
            }
        }
        //搜索
        function search() {
            current_page = 1;
            if(current == 1){
                showuser();
            }
            else if (current == 2){
                showcourse();
            }
        }
        function parseCookies() {
            var cookies = {};
            var cookieString = document.cookie;
            var cookieArray = cookieString.split('; ');

            for (var i = 0; i < cookieArray.length; i++) {
                var cookie = cookieArray[i].split('=');
                var name = cookie[0];
                var value = cookie[1];
                cookies[name] = value;
            }

            return cookies;
        }
        //添加用户
        function adduser(){
            var data={
                user : user,
                name : $("#addName").val(),
                username : $("#addUsername").val(),
                password : $("#addPassword").val()
            };
            $.ajax({
                url: "adduser",
                type:"POST",
                data: data,
                dataType:"text",
                success:function(data){
                    if(data == "true"){
                        showmessage("添加成功");
                    }
                    showuser();
                    $("#addModal").modal('hide');
                },
                error: function(jqXHR, textStatus, errorThrown){
                    showmessage("添加用户失败");
                    console.log(textStatus + ': ' + errorThrown);
                }
            });
        }
        //删除用户
        function deleteuser(n){
            var data = {
                user : user,
                userid : n
            };
            $.ajax({
                url: "deleteuser",
                type:"POST",
                data: data,
                dataType:"text",
                success:function(data){
                    if(data == "true"){
                        showmessage("删除成功");
                    }
                    showuser();
                },
                error: function(jqXHR, textStatus, errorThrown){
                    showmessage("删除用户失败");
                    console.log(textStatus + ': ' + errorThrown);
                }
            });
        }
    </script>
    <!-- 修改数据和保存数据，修改密码 -->
    <script>
        //修改用户
        function editRow(button) {
          // 获取当前行的数据
          var row = button.closest('tr');
          userid = row.cells[0].textContent;
          var name = row.cells[1].textContent;
          var username = row.cells[2].textContent;
          var password = row.cells[3].textContent;
      
          // 将数据填充到修改表单中
          document.getElementById('editName').value = name;
          document.getElementById('editUsername').value = username;
          document.getElementById('editPassword').value = password;
      
          // 显示修改模态框
          $('#editModal').modal('show');
        }  
        //保存修改
        function saveChanges() {
          // 获取修改后的数据
          var data = {
            user: user,
            user_id : userid,
            name: document.getElementById('editName').value,
            username: document.getElementById('editUsername').value,
            password: document.getElementById('editPassword').value
          };
      
          $.ajax({
                url: "changeuser",
                type:"POST",
                data: data,
                dataType:"text",
                success:function(data){
                    if(data == "true"){
                        showmessage("修改成功");
                    }
                     showuser();
                },
                error: function(jqXHR, textStatus, errorThrown){
                    showmessage("修改失败");
                    console.log(textStatus + ': ' + errorThrown);
                }
            });
      
          // 关闭模态框
          $('#editModal').modal('hide');
        }
        //修改密码
        function changepassword(){
            var data={
                adminerid : allCookies["adminer_id"],
                oldpassword : $(oldPassword).val(),
                newpassword : $(newPassword).val()
            };
            if(data.newpassword != $(confirmPassword).val()){
                showmessage("两次密码不一致，请重新输入");
                return;
            }
            if(data.oldpassword == "" || data.newpassword == "" || $(confirmPassword).val() == ""){
                showmessage("输入框不可以为空");
                return;
            }

            $.ajax({
                url: "changepassword",
                type:"POST",
                data: data,
                dataType:"text",
                success:function(data){
                    if(data == "true"){
                        showmessage("修改密码成功");
                    }
                    else{
                        showmessage("原密码错误");
                    }
                },
                error: function(jqXHR, textStatus, errorThrown){
                    showmessage("修改密码失败");
                    console.log(textStatus + ': ' + errorThrown);
                }
            });

            $('#changepasswordModal').modal('hide');
        }
    </script>
</body>    
</html>